package com.hdl.servlet.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hdl.entity.MallProduct;
import com.hdl.service.MallProductService;
import com.hdl.service.impl.MallProductServiceImpl;

@WebServlet("/admin/mall-list.let")
public class MallProductListServlet extends HttpServlet{
	
	private MallProductService mp = new MallProductServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int current = 1;
		try{
			current = Integer.valueOf(request.getParameter("current"));
		}catch(Exception ex){
		}
		
		int rowMax = 5;
		try{
			rowMax = Integer.valueOf(request.getParameter("pageSize"));
		}catch(Exception ex){
		}
		
		
		String lk=request.getParameter("like");
		int typeid=0;
		try {
			typeid=Integer.valueOf(request.getParameter("roleid"));
		
		} catch (Exception e) {
			typeid=0;
		}
		
		int index=(current-1)*rowMax;
		
		int total=0;
		total=mp.Total(typeid, lk);
		System.out.println("total"+total);
		
		List<MallProduct> list = mp.SelectProduct(index, rowMax, typeid, lk);
		System.out.println("servlet++++"+list);
		 request.setAttribute("rowMax", rowMax);
		 request.setAttribute("roleid", typeid);
		 request.setAttribute("total", total);
	     request.setAttribute("list", list);
	     request.setAttribute("like", lk);
	     request.getRequestDispatcher("/admin/mall/mall-product.jsp").forward(request, response);;
	}
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	doGet(req, resp);
    }
}
